package logic

import (
	"context"
	"tb/models/mysql"

	"tb/tbrpc/internal/svc"
	"tb/tbrpc/tbrpc"

	"github.com/zeromicro/go-zero/core/logx"
)

type ProductAddLogic struct {
	ctx    context.Context
	svcCtx *svc.ServiceContext
	logx.Logger
}

func NewProductAddLogic(ctx context.Context, svcCtx *svc.ServiceContext) *ProductAddLogic {
	return &ProductAddLogic{
		ctx:    ctx,
		svcCtx: svcCtx,
		Logger: logx.WithContext(ctx),
	}
}

func (l *ProductAddLogic) ProductAdd(in *tbrpc.ProductAddRequest) (*tbrpc.ProductAddResponse, error) {
	// todo: add your logic here and delete this line

	var product mysql.Product
	product = mysql.Product{
		Title:  in.Title,
		Price:  float64(in.Price),
		Number: int(in.Number),
	}
	mysql.DB.Debug().Create(&product)

	return &tbrpc.ProductAddResponse{
		ProductId: int64(product.ID),
	}, nil
}
